package second50;

public class T0066 {
    public int[] plusOne(int[] digits) {
        int carry = 1;
        for (int i = digits.length - 1; i >= 0; i--) {
            int sum = carry + digits[i];
            if (sum == 10) {
                digits[i] = 0;
            } else {
                digits[i] = sum;
                carry = 0;
                break;
            }
        }
        if (carry == 1) {
            int[] d = new int[digits.length + 1];
            d[0] = 1;
            return d;
        }
        return digits;
    }
}
